$(function () {
    var $jobLogTableForm = $(".trans-table-form");
    var settings = {
        url: ctx + "trans/list",
        pageSize: 10,
        queryParams: function (params) {
            return {
                pageSize: params.limit,
                pageNum: params.offset / params.limit + 1,
                beanName: $jobLogTableForm.find("input[name='beanName']").val().trim(),
                methodName: $jobLogTableForm.find("input[name='methodName']").val().trim(),
                status: $jobLogTableForm.find("select[name='status']").val()
            };
        },
        columns: [{
            checkbox: true
        },
            {
                field: 'transSeqNo',
                title: '平台流水号'
            }, {
                field: 'transDateTime',
                title: '交易日期'
            }, {
                field: 'transId',
                title: '交易类型'
            }, {
                field: 'merId',
                title: '商户号'
            }, {
                field: 'transStatus',
                title: '交易状态',
                formatter: function (value, row, index) {
                    if (value === '01') return '<span class="badge badge-danger">失败</span>';
                    if (value === '00') return '<span class="badge badge-success">成功</span>';
                    if (value === null) return '<span class="badge badge-danger">未处理</span>';
                    if (value === '07') return '<span class="badge badge-danger">处理中</span>';
                }
            }, {
                field: 'transAmt',
                title: '交易金额'
            }, {
                field: 'transMerSeqNo',
                title: '商户流水'
            }, {
                field: 'transMerDateTime',
                title: '商户交易时间'
            }
        ]
    };

    $MB.initTable('transTable', settings);
});

function search() {
    $MB.refreshTable('transTable');
}

function refresh() {
    $(".trans-table-form")[0].reset();
    search();
}



function exportTransExcel() {
    $.post(ctx + "trans/excel", $(".trans-table-form").serialize(), function (r) {
        if (r.code === 0) {
            window.location.href = "common/download?fileName=" + r.msg + "&delete=" + true;
        } else {
            $MB.n_warning(r.msg);
        }
    });
}

function exportTransCsv() {
    $.post(ctx + "trans/csv", $(".trans-table-form").serialize(), function (r) {
        if (r.code === 0) {
            window.location.href = "common/download?fileName=" + r.msg + "&delete=" + true;
        } else {
            $MB.n_warning(r.msg);
        }
    });
}